<template>
	<!-- 我的里面的个人资料 -->
	<view class="page">
		<view class="content">
			<view class="rowlosn" @click="modifyname">
				<text class="title">
					<text>修改昵称</text>
				</text>
				<text class="text">
					<text class="iconfont icon-right-arrow"></text>
				</text>
			</view>
			<view class="rowlosn" @click="genders">
				<text class="tit">
					<text>修改性别</text>
				</text>
				<text class="tiv">
					<text class="iconfont icon-right-arrow"></text>
				</text>
			</view>
		</view>
		<view>
			<!--弹窗-->
			<modal style='' v-if="showPop" title="编辑" confirm-text="确定" cancel-text="取消" @cancel="cancelPop" @confirm="confirmPop">
				<input style="border-top: 1px solid #F3F3F3;border-bottom: 1px solid #F3F3F3;" type='text' placeholder="请输入..."
				 v-model:value="valuename" />
			</modal>
		</view>
		<view class="popup">
			<!--弹窗-->
			<modal style='' v-if="showPop1" title="选择性别" confirm-text="确定" cancel-text="取消" @cancel="cancelPop1" @confirm="confirmPop1">
				<view style="margin-left: 144rpx;">
					 <radio-group class="radio-group" :bindchange="radioChange">
						<label class="radio" ><radio name="sex" value="secrecy" checked="true">保密</radio> </label>
						<label class="radio" ><radio name="sex" value="male">男</radio></label>
						<label class="radio" ><radio name="sex" value="female">女</radio></label>
					 </radio-group>
				</view>
			</modal>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				showPop: false, //弹窗
				showPop1: false, //弹窗
				nickname: '', //新用户名
				valuename: '',
				newsex: '' //新性别
			}
		},
		onLoad: function(e) {
			uni.setNavigationBarTitle({
				title: "修改资料"
			});
		},
		methods: {
			// 修改昵称
			modifyname() {
				this.showPop = true
			},
			//弹窗
			confirmPop() { //确认
				this.nickname = this.valuename
				console.log(this.nickname)
				if (this.nickname != '') {
					this.showPop = false
					uni.request({
						url: 'http://192.168.1.54:8081/m.api?_gp=user&_mt=syncUserInfo&nickName='+this.nickname+'&nickname='+uni.getStorageSync('nickname')+'&avatarUrl=&gender=&birthday=&ACCESSTOKEN= ', 
						header:{
							'accesstoken': uni.getStorageSync('accessToken')
						},
						success: (res) => {
							console.log(res)
							if (res.data.errmsg == "成功") {
								uni.setStorageSync('nickname', this.nickname)
								uni.showToast({
									title: '修改成功',
									success: () => {
										setTimeout(() => {
											uni.navigateBack();
										}, 1000)
									}
								})
							} else {
								console.log(res.data.errmsg)
							}
						}
					})
				} else {
					this.showPop = false
					uni.showToast({
						title: '输入不能为空',
						icon: 'none',
						duration: 2000
					})
				}
			},
			cancelPop() { //取消
				this.showPop = false
			},
			// 修改性别
			genders() {
				this.showPop1 = true
			},
			//弹窗
			confirmPop1() { //确认
				this.showPop1 = false
				uni.request({
					url: 'http://192.168.1.54:8081/m.api', // 仅为示例，并非真实的接口地址
					method:"GET",
					data:{
						"_gp":"user",
						"_mt":"syncUserInfo",
						"nickName":123,
						"nickname":321,
						"avatarUrl":123,
						"gender":"",
						"birthday":"",
						"ACCESSTOKEN":""
					},
					header: {
						'accesstoken': uni.getStorageSync('token') // 默认值
					},
					success: (res) => {
						console.log(res)
						if (res.data.errmsg == "成功") {
							
						} else {
							console.log(res.data.errmsg)
						}
					}
				})
			},
			cancelPop1() { //取消
				this.showPop1 = false
			},
		},
	}
</script>

<style scoped="scoped">
	.page {width: 100%;border-top: 7px solid #F8F8F8;background-color: #F8F8F8;height: 100vh;}
	.rowlosn {display: flex;-webkit-box-align: center;align-items: center;position: relative;padding: 0 15px;height: 55px;background: #fff;border-bottom: 1px solid #F1F3F6;}
	.rowlosn .title {-webkit-flex-shrink: 0;flex-shrink: 0;width: 60px;font-size: 15px;color: #303133;}
	.rowlosn .text {-webkit-box-flex: 1;-webkit-flex: 1;flex: 1;font-size: 15px;color: #aaaaaa;text-align: right;}
	.tcp {width: 100%;font-size: 14px;color: #aaaaaa;text-align: center;position: absolute;bottom: 100px;}
</style>
